package com.chinadaas.hangzhou.archetypeweb.config;

import io.etcd.jetcd.Client;
import io.etcd.jetcd.KV;
import io.etcd.jetcd.Watch;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by zhangde on 2017/6/13. 下午1:33
 */
@Configuration
public class EtcdConfig {

    @Value("${etcd.hosts}")
    private String url;

    public Client getClient() {
        String[] urls = url.split(",", -1);
        return Client.builder().endpoints(urls).build();
    }

    @Bean
    public KV kv() {
        return getClient().getKVClient();
    }

    @Bean
    public Watch getWatchClient() {
        return getClient().getWatchClient();
    }

}
